#pragma once

#include "SkinnedText.h"

class CSkinnedEdit : public CSkinnedTextImpl<CSkinnedEdit, CEdit>
{
public:
  CSkinnedEdit(COLORREF clrText = CTheme::clrEditBox, CFontHandle fntText = CTheme::fntEditBox.font.m_hFont, CBrushHandle brBackground = CTheme::brEditBox.m_hBrush)
    : CSkinnedTextImpl<CSkinnedEdit, CEdit>(clrText, fntText, brBackground)
  {}

	HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
			DWORD dwStyle = WS_CHILD | WS_BORDER | WS_VISIBLE | ES_AUTOHSCROLL, DWORD dwExStyle = ES_EX_CLEARONBACKPRESSHOLD,
			ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
	{
		return CSkinnedTextImpl<CSkinnedEdit, CEdit>::Create(hWndParent, rect, szWindowName, dwStyle, dwExStyle, MenuOrID, lpCreateParam);
	}

// Message map and handlers
	BEGIN_MSG_MAP(CSkinnedEdit)
    MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnColorStatic)

    MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
    MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)

    CHAIN_MSG_MAP(CSkinnedTextImpl)
	END_MSG_MAP()

  LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  {
    switch(wParam)
    {
    case VK_TBACK:
    case VK_TACTION:
    case VK_TUP:
    case VK_TDOWN:
    case VK_TSOFT1:
    case VK_TSOFT2:
    case VK_THOME:
      SendMessage(::GetParent(m_hWnd), uMsg, wParam, lParam);
      return bHandled = TRUE;

    case VK_TTALK:
    case VK_TEND:
		/*
      if (Settings::enablePhoneKeyHook)
      {
        SendMessage(::GetParent(m_hWnd), uMsg, wParam, lParam);
        return bHandled = TRUE;
      }*/
		;
    }
    return 0;
  }

  LRESULT OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  {
    switch(wParam)
    {
    case VK_TBACK:
    case VK_TACTION:
    case VK_TUP:
    case VK_TDOWN:
    case VK_TSOFT1:
    case VK_TSOFT2:
    case VK_THOME:
      SendMessage(::GetParent(m_hWnd), uMsg, wParam, lParam);
      return bHandled = TRUE;

    case VK_TTALK:
    case VK_TEND:
		/*
      if (Settings::enablePhoneKeyHook)
      {
        SendMessage(::GetParent(m_hWnd), uMsg, wParam, lParam);
        return bHandled = TRUE;
      } */
		;
    }
    return 0;
  }

// Interface
  void Backspace()
  {
    CString txt;
    GetWindowText(txt);
    if (txt.GetLength() > 0)
    {
      txt.Truncate(txt.GetLength() - 1);
      SetWindowText(txt);
      this->SetSel(txt.GetLength(), -1);
    }
  }
};
